/*
  将下面异步代码使用 Promise 的方法改进
  尽量用看上去像同步代码的方式
  setTimeout(function () {
    var a = 'hello'
    setTimeout(function () {
      var b = 'lagou'
      setTimeout(function () {
        var c = 'I ♥ U'
        console.log(a + b +c)
      }, 10)
    }, 10)
  }, 10)
*/


/**
 * 解法一
 */
let p1 = new Promise((resolve, reject)=>{
    setTimeout(function () {
        var a = 'hello';
        resolve(a);
    }, 10)
});

let p2 = new Promise((resolve, reject)=>{
    setTimeout(function () {
        var b = 'lagou';
        resolve(b);
    }, 10)
});

let p3 = new Promise((resolve, reject)=>{
    setTimeout(function () {
        var c = 'I ♥ U';
        resolve(c);
    }, 10)
});

Promise.all([p1,p2,p3]).then(value=>console.log('解法一：',value.join('')))

/**
 * 解法二只做练习
 * 尽量看起来同步，所以解法一更符合要求
 */
let p4 = new Promise((resolve, reject)=>{
    setTimeout(function () {
        var a = 'hello';
        resolve(a);
    }, 2000)
});
p4.then(value =>{
    return new Promise((resolve, reject) => {
        setTimeout(function () {
            var b = 'lagou';
            resolve(value + b);
        }, 2000)
    });
}).then(value =>{
    return new Promise((resolve, reject) => {
        setTimeout(function () {
            var c = 'I ♥ U';
            resolve(value + c);
        }, 2000)
    });
}).then(value => console.log('解法二：', value));
